<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="数据日期" prop="sjrq">
        <el-date-picker
          v-model="queryParams.sjrq"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="date"
          range-separator="-"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['buss:xdywonline:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="xdywonlineList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="数据日期" align="center" prop="sjrq"   />
      <el-table-column label="机构" align="center" prop="orgId" :formatter="orgIdFormat" />
      <el-table-column label="个人线上业务户数" align="center" prop="grxshs"   />
      <el-table-column label="个人线上贷款业务余额" align="center" prop="grxsye"   />
      <el-table-column label="30w个人消费贷款客户数" align="center" prop="xfhs"   />
      <el-table-column label="30w个人消费贷款余额" align="center" prop="xfje"   />
      <el-table-column label="50w个人经营性贷款客户数" align="center" prop="jyhs"  />
      <el-table-column label="50w个人经营性贷款余额" align="center" prop="jyje"  />
      <el-table-column label="30万元以内的个人按揭贷款客户数" align="center" prop="ajhs"   />
      <el-table-column label="30万元以内的个人按揭贷款款余额" align="center" prop="ajje"   />
      <el-table-column label="扶贫小额信贷客户数" align="center" prop="fphs"   />
      <el-table-column label="扶贫小额信贷余额" align="center" prop="fpje"   />
      <el-table-column label="余额占比=个人线上贷款业务余额/(单户授信50万元" align="center" prop="yezb"   />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改线上信贷业务占比-信贷类报3对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    
    <div>
      <div id="xsywzb" style="width:100%;height: 375px;margin-top: 50px;"></div>
    </div>
  </div>
</template>

<script>
import { listXdywonline, getXdywonline, delXdywonline, addXdywonline, updateXdywonline } from "@/api/buss/bi/xdywonline";

export default {
  name: "Xdywonline",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 线上信贷业务占比-信贷类报3表格数据
      xdywonlineList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 机构字典
      orgIdOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sjrq: null,
        orgId: null,
        grxshs: null,
        grxsye: null,
        xfhs: null,
        xfje: null,
        jyhs: null,
        jyje: null,
        ajhs: null,
        ajje: null,
        fphs: null,
        fpje: null,
        yezb: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      qushiDate: [],
      qushiyezb: []
    };
  },
  created() {
    this.getList();
    this.getQstList();
    this.getDicts("sys_org_id").then(response => {
      this.orgIdOptions = response.data;
    });
  },
  methods: {
    /** 查询线上信贷业务占比-信贷类报3列表 */
    getList() {
      this.loading = true;
      listXdywonline(this.queryParams).then(response => {
        this.xdywonlineList = response.data.xsxdywzb.rows;
        this.total = response.data.xsxdywzb.total;
        this.loading = false;
      });
    },
    /** 查询趋势图列表 */
    getQstList() {
      listXdywonline(this.queryParams).then(response => {
        for (var i = 0; i < response.data.xsxdywzbhz.length; i++) {
             this.qushiDate.push(response.data.xsxdywzbhz[i].sjrq);
             this.qushiyezb.push(response.data.xsxdywzbhz[i].yezb);
        }
        this.yxyjzst();  //趋势图
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sjrq: null,
        orgId: null,
        grxshs: null,
        grxsye: null,
        xfhs: null,
        xfje: null,
        jyhs: null,
        jyje: null,
        ajhs: null,
        ajje: null,
        fphs: null,
        fpje: null,
        yezb: null
      };
      this.resetForm("form");
    },
    // 机构字典翻译
    orgIdFormat(row, column) {
      return this.selectDictLabel(this.orgIdOptions, row.orgId);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sjrq)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加线上信贷业务占比-信贷类报3";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const sjrq = row.sjrq || this.ids
      getXdywonline(sjrq).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改线上信贷业务占比-信贷类报3";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sjrq != null) {
            updateXdywonline(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addXdywonline(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sjrqs = row.sjrq || this.ids;
      this.$confirm('是否确认删除线上信贷业务占比-信贷类报3编号为"' + sjrqs + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delXdywonline(sjrqs);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('buss/reportLsb/xsxdywzbExport', {
        ...this.queryParams
      }, `线上信贷业务占比.xlsx`)
    },
    yxyjzst(){
      let xsywzbChart = this.$echarts.init(document.getElementById('xsywzb'))
      xsywzbChart.setOption({
            tooltip: {
            	trigger: 'axis'
            },
            legend: {
            	textStyle: {
            		fontSize: 18
            	},
            	data: ['业务占比']
            },
            grid: {
            	left: '8%',
            	right: '4%',
            	bottom: '6%',
            	ntainLabel: true
            },
            xAxis: {
            	type: 'category',
            	boundaryGap: false,
            	data:  this.qushiDate
            },
            yAxis: {
            	type: 'value'
            },
            series: [
    
            	{
            		name: '业务占比',
            		type: 'line',
            		//stack: '总量',
            		data: this.qushiyezb
            	}
            ]
        });
    }
  }
};
</script>
